<template>
	<view class="p60">
		<view class="title">
			绑定新手机号
		</view>

		<view class="input-phone">
			<input @input="phoneChange" class="uni-input" confirm-type="search" placeholder="请输入您的手机号" />
		</view>

		<view class="line">

		</view>

		<view class="input-code-box">
			<view class="input-code">
				<input @input="codeChange" class="uni-input" confirm-type="search" placeholder="请输入验证码" />
			</view>

			<view class="btn-send" @click="sendPhoneMsg">
				{{countdown}}
			</view>
		</view>

		<view class="line">

		</view>

		<view class="btn-submit" @click="submit">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					phone: null,
					code: null
				},
				timer: null,
				countdown: '获取验证码',
				disabled:false
			}
		},
		methods: {
			sendPhoneMsg() {
				if(this.disabled)return;
				let that = this;
				this.$request.get({
					url: 'sendPhoneMsg',
					data: {
						phone: this.formData.phone
					},
				}).then(res => {
					that.countdown = 60;
					that.timer = setInterval(that.countDown, 1000);
				}, res => {});
			},
			countDown() {
				var that = this;
				if (!that.countdown) {
					that.disabled = false;
					that.timestatus = false;
					that.countdown = '获取验证码';
					clearInterval(that.timer);
				} else {
					that.disabled = true;
					--that.countdown;
				}
			},
			verifyFormData(cb) {
				if (this.formData.phone === null) {
					uni.showToast({
						title: '请输入手机号',
						duration: 2000,
						icon: 'none'
					})
					return;
				}

				if (this.formData.code === null) {
					uni.showToast({
						title: '请输入验证码',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				cb && cb();

			},
			submit() {
				this.verifyFormData(() => {
					this.$request.get({
						url: 'setUserPhone',
						data: this.formData,
						loadingTip:'正在处理...'
					}).then(res => {
						uni.showToast({
							title: '信息更新成功！',
							duration: 2000,
							icon: 'none'
						})
						setTimeout(() => {
							uni.reLaunch({
								url:'/pagesB/expert/expert'
							})
						}, 1000);
					}, res => {});
				});

			},
			phoneChange(e) {
				this.formData.phone = e.detail.value;
			},
			codeChange(e) {
				this.formData.code = e.detail.value;
			}
		}
	}
</script>

<style>
	.btn-send {
		color: #268CFF;
		font-size: 32upx;
	}

	.p60 {
		padding: 0 60upx;
	}

	.input-code-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		margin-top: 80upx;
	}

	.input-phone {
		margin-top: 100upx;
	}

	.line {
		width: 100%;
		height: 2upx;
		background: rgba(239, 239, 239, 1);
		box-shadow: 0px 6upx 24upx 0upx rgba(56, 73, 184, 0.04);
		border-radius: 16upx;
		margin: 20upx auto;
	}

	.btn-submit {
		margin-top: 180upx;
		width: 620upx;
		height: 98upx;
		background: linear-gradient(183deg, rgba(11, 200, 253, 1) 0%, rgba(4, 151, 250, 1) 100%);
		border-radius: 50upx;

		color: #FFFFFF;
		font-size: 36upx;
		line-height: 98upx;
		text-align: center;
	}

	.uni-input {
		font-size: 32upx;
		color: #999999;
	}

	.title {
		font-size: 48upx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(72, 82, 107, 1);
		margin-top: 120upx;
	}
</style>